package com.service.zy;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.zy.UnitDao;
import com.entity.Unit;
import com.service.ServiceException;

@Service
@Transactional(rollbackFor=ServiceException.class)
public class UnitService {
	@Autowired
	private UnitDao unitDao;
	/**
	 * 添加一个单位
	 * @param unit
	 * @throws ServiceException
	 */
	public void addOne(Unit unit) throws ServiceException {
		try {
			unitDao.save(unit);
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 删除一个单位
	 * @param id
	 * @throws ServiceException
	 */
	public void delOne(Long id) throws ServiceException{
		try {
			unitDao.delete(id);
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 查询所有单位
	 * @return
	 * @throws ServiceException
	 */
	public List<Unit> findAll() throws ServiceException{
		try {
			return (List<Unit>) unitDao.findAll();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
}
